package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Commodity;
import cn.wolfcode.luowowo.article.mapper.CommodityMapper;
import cn.wolfcode.luowowo.article.service.ICommodityService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CommodityServiceImpl implements ICommodityService {

    @Autowired
    private CommodityMapper commodityMapper;

    @Override
    public void saveOrUpdate(Commodity commodity) {

        if(commodity.getId() == null){
            commodityMapper.insert(commodity);
        }else{
            commodityMapper.updateByPrimaryKey(commodity);
        }
    }

    @Override
    public void deleteByPrimaryKey(Long id) {
        commodityMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Commodity get(Long id) {
        return commodityMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Commodity> listAll() {
        return commodityMapper.selectAll();
    }
}
